package com.xinshujia.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xinshujia.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * *************************************
 * *   @author: 野狼上校               **
 * *   @since: 2024-07-11 15:40       **
 * *   @version: 1.0                  **
 * *************************************
 * <p>
 *     用户持久化
 *     基本查询和分页查询
 */
@Mapper
public interface UserDao extends BaseMapper<UserEntity>{
    /**
     * 根据用户名查询用户
     * @param username 用户名
     * @return 用户
     */
    @Select("SELECT * FROM auth_user u WHERE u.username = #{username};")
    UserEntity loadUserByUsername(@Param("username") String username);

    /**
     * 根据手机号查询用户
     * @param phone 手机号
     * @return 用户
     */
    @Select("SELECT * FROM auth_user u WHERE u.phone = #{phone};")
    UserEntity loadUserByPhone(@Param("phone") String phone);

    /*单个属性更新*/
    @Update("UPDATE auth_user SET enabled = #{enabled} WHERE id = #{id};")
    int patchUser(@Param("id") Long id, @Param("enabled") int enabled);
}